#include <bits/c++config.h>
#include <iostream>
#include <ostream>
#include <istream>
#include <string>
using namespace std;
class complex{
friend bool operator>>(istream &in,complex &Z);
friend ostream& operator<<(ostream &out,const complex &Z);
	private:
		double Re;
		double Im;
	public:
		complex(double Re=0,double Im=0);
		complex operator+(const complex &c);
		complex operator-(const complex &c);
		complex operator*(const complex &c);
		complex conj();
		friend complex operator*(int z,const complex &Z);
};


int main()
{
	complex a(3,4);
	complex c;
	cout<<"Enter a complex number (q to quit):"<<endl;
	while(cin>>c){
		cout<<"c is "<<c<<endl;
		cout<<"complex conjugate is "<<c.conj()<<endl;
		cout<<"a is "<<a<<endl;
		cout<<"a + c is "<<a+c<<endl;
		cout<<"a - c is "<<a-c<<endl;
		cout<<"a * c is "<<a*c<<endl;
		cout<<"2 * c is "<<2*c<<endl;
		cout<<"Enter a complex number (q to quit):"<<endl;
	}
	cout<<"Done!"<<endl;
	return 0;
}

complex::complex(double Re,double Im){
	this->Re=Re;
	this->Im=Im;
}
ostream& operator<<(ostream &out,const complex &Z)
{
	out<<'('<<Z.Re<<","<<Z.Im<<"i"<<")";
	return out;
}
bool operator>>(istream &in,complex &Z)
{
	cout<<"real:";
	string a;
	cin>>a;
	if(a=="q"){
//		cout<<a<<endl;
		return false;
	}else{
		double re,im;
		re=stod(a);
		Z.Re=re;
//		cout<<Z.Re<<endl;
		cout<<"imaginary:";
		cin>>im;
		Z.Im=im;
//		cout<<Z.Im<<endl;
	}
	return true;
}
complex complex::operator+(const complex &c)
{
	complex z;
	z.Im=this->Im+c.Im;
	z.Re=this->Re+c.Re;
	return z;
}
complex complex::operator-(const complex &c)
{
	complex z;
	z.Im=this->Im-c.Im;
	z.Re=this->Re-c.Re;
	return z;
}
complex complex::operator*(const complex &c)
{
	complex z;
	z.Re=this->Re*c.Re-this->Im*c.Im;
	z.Im=this->Re*c.Im+this->Im*c.Re;
	return z;
}
complex operator*(int z,const complex &Z){
	complex A;
	A.Re=Z.Re*z;
	A.Im=Z.Im*z;	
	return A;
}
complex complex::conj()
{
	complex Conj;
	Conj.Re=this->Re;
	Conj.Im=-this->Im;
	return Conj;
}
